package com.itcs.app.pay.nowpay;

import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.itcs.app.pay.PayPlatformAdapter;
import com.itcs.app.pay.model.QrcodeFilterRes;
import com.itcs.app.pay.model.QrcodePayModel;
import com.itcs.app.pay.model.QrcodePayRes;
import com.itcs.app.pay.model.TradePayModel;
import com.itcs.app.pay.model.TradePayRes;
import com.itcs.app.pay.nowpay.service.NowpayService;
import com.itcs.app.util.ParamMap;

/**
 * 现在支付平台
 * 
 * @author LiuPeng
 * @date 2018年3月24日
 * 
 */
@Component
public class NowPayPlatform implements PayPlatformAdapter {

	private Log logger = LogFactory.getLog(getClass());

	public final static String TYPE = "nowpay";

	@Autowired
	private NowpayService nowpayService;

	@Override
	public String getPayPlatformType() {
		return TYPE;
	}

	@Override
	public QrcodeFilterRes qrcodeFilter(HttpServletRequest request, String payChannelCode) {
		return new QrcodeFilterRes(ParamMap.init(request), null);
	}

	@Override
	public QrcodePayRes qrcode(QrcodePayModel qrcodePayModel) {
		Map<String, String> data = null;
		try {
			data = nowpayService.buildQrcode(qrcodePayModel);
		} catch (Exception e) {
			logger.error("现在支付主扫失败处理," + e.getMessage(), e);
		}
		return new QrcodePayRes("/wap3", data);
	}

	@Override
	public TradePayRes tradePay(TradePayModel tradePayModel) {
		return nowpayService.tradePay(tradePayModel);
	}

}
